define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {

		$scope.form.father_id=params.father_id;
		$scope.form.fk_unit='self';
		httpService.post(app.urls.expert_selectById,{"id":params.id},function(data){
			if("0000" === data.code){
				$scope.user = data.data;
			}else{
				alert(data.msg);
			}
		});
		
		//查询所有单位
		httpService.post(app.urls.unit_selectUnit,{},function(data){
			if("0000" === data.code){
				$scope.units = data.data;
			}else{
				alert(data.msg);
			}
		});
		
		function confirmEnding(str, target) {
			  var start = str.length-target.length;
			  var arr = str.substr(start,target.length);
			  if(arr == target){
			    return true;
			  }
			 return false;
		}
		
		$scope.saveForm = function(){
			if($scope.formCheck()) {
				if($scope.user.sfzjh=="" || $scope.user.sfzjh==null){
	 				$scope.user.sfzjh='9999999'+$scope.user.phone
	 			}else{
	 				if(confirmEnding($scope.user.sfzjh,$scope.user.phone)){
	 					
	 				}else{
		 				var idcard = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
		 				if (idcard.test($scope.user.sfzjh)) {
		 				} else {
		 					eventBusService.publish('modal.alert', {"title":"操作提示","content":"请输入正确身份证件号或填写以手机号结尾的18位数字"});
		 					return;
		 				}
	 				}
	 			}
				$scope.user.id=$scope.user.fk_user=params.id;
				httpService.post(app.urls.expert_selectRepeat,$scope.user,function(data) {
					if ("0000" === data.code) {
						// httpService.post(app.urls.user_update,$scope.user,function(data) {
						// 	if ("0000" === data.code) {
								httpService.post(app.urls.expert_update, $scope.user, function (data) {
									if("0000" === data.code){
										var menu = {"url": "modules/content/usermanagement/expert/list?father_id=" + params.father_id+ "&sheet=" + params.sheet+ "&field=" + params.field+ "&type=" + params.type};
										if(params.sheet=='undefined'){
											eventBusService.publish("modules.content.load",menu);
										}else {
											eventBusService.publish("modules.content.load",menu);
										}
									}else{
										alert(data.msg);
									}
								});
						// 	} else {
						// 		alert(data.msg);
						// 	}
						// });
					}else {
						alert(data.msg);
					}
				});
			}
		}
		//返回
		$scope.goback = function(){
			var menu = {"url":"modules/content/usermanagement/expert/list?father_id="+params.father_id};
			if(params.sheet!='undefined'){
				 menu.url = menu.url + "&sheet="+params.sheet;
				 eventBusService.publish("modules.content.load", menu);
			 }else{
				 eventBusService.publish("modules.welcome.load", menu);
			 }
		}
		//日期插件
		$('#'+$scope.controllerName+' .datepicker').datepicker({
			onSelect: function(dateText, inst) {
				eval("$scope." + $(this).attr('ng-model') + "='"+$(this).val()+"'");
			}
		});
		$('#'+$scope.controllerName+' .datepicker').datepicker('option', 'dateFormat','yy-mm-dd');//set dateFormat
}}});